package com.square.service.common.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

/**
 * 异常工具类
 *
 * @author : 王苏
 * @since : 2021/3/18 17:16
 */
@Slf4j
public class ExceptionUtil {
    /**
     * 获取异常全部信息
     *
     * @param ex
     * @return
     */
    public static String getExceptionAllinformation(Exception ex) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        PrintStream pout = new PrintStream(out);
        ex.printStackTrace(pout);
        String ret = new String(out.toByteArray());
        pout.close();
        try {
            out.close();
        } catch (Exception e) {
            log.info("获取异常全部信息失败：", e);
        }
        return ret;
    }
}
